import { User } from '@entity/user'
import MemberFilter from './filter/Index.vue';
import { Component, Vue } from 'vue-property-decorator'
import axios from '@axios/user'
import Avatar from '@avatar'

@Component({
    components: {
        Avatar, MemberFilter
    }
})
export class FindMember extends Vue {

    /** 用户列表 */
    private userList: Array<User> = [];

    created() {
        this.doSearch({});
    }

    /**
     * 当输入的关键字或选择的选项发生改变时调用
     */
    private onDataChange(data: any) {
        let kw: string = data.searchKeywords;
        let requestData: any = {};
        if (kw.isEmail()) {
            requestData.email = kw;
        } else if (kw.isTelephone()) {
            requestData.tel = kw;
        } else if (!kw.isEmpty()){
            requestData.name = kw;
        }
        if (!data.first.isEmpty()) {
            requestData.goodness = data.first;
        }
        this.doSearch(requestData);
    }

    /**
     * 执行搜索请求
     * @param data 请求参数
     */
    private doSearch(data: any): void {
        axios.base.queryByInfo(data).then((res: Array<User>) => {
            this.userList = res;
        })
    }

}